home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / Asm / Demos / Stars4.s < prev    next >
Encoding:
Text File  |  1998-05-07  |  7.8 KB  |  288 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;This is a demo of a triple buffered starfield.  I didn't orginally write
  3. ;this starfield code, but it was very old so it needed a fair bit of
  4. ;cleaning up to work with the library.  It now runs in 4 colours for a
  5. ;little more depth too...
  6.  
  7.     INCDIR    "INCLUDES:"
  8.     INCLUDE    "dpkernel/dpkernel.i
  9.  
  10. NSTARS    =    800                     ;Number of stars
  11.  
  12. XSPEED    =    -4
  13. YSPEED    =    6
  14. ZSPEED    =    2
  15.  
  16. SCRWIDTH  =    320
  17. SCRHEIGHT =    256
  18.  
  19.     SECTION    "Stars",CODE
  20.  
  21. ;==========================================================================;
  22. ;                             INITIALISE DEMO
  23. ;==========================================================================;
  24.  
  25.     STARTDPK
  26.  
  27. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  28.     move.l    DPKBase(pc),a6
  29.     lea    ScreenTags(pc),a0
  30.     sub.l    a1,a1
  31.     CALL    Init
  32.     tst.l    d0
  33.     beq.s    .Exit
  34.  
  35.     moveq    #ID_JOYDATA,d0    ;Get joydata structure.
  36.     CALL    Get
  37.     move.l    d0,JoyData
  38.     beq.s    .Exit
  39.     move.l    d0,a0    ;Initialise the joydata structure.
  40.     sub.l    a1,a1
  41.     CALL    Init
  42.     tst.l    d0
  43.     beq.s    .Exit
  44.  
  45.     move.l    Screen(pc),a0
  46.     CALL    Display
  47.  
  48.     bsr.s    Main
  49.  
  50. .Exit    move.l    DPKBase(pc),a6
  51.     move.l    JoyData(pc),a0
  52.     CALL    Free
  53.     move.l    Screen(pc),a0
  54.     CALL    Free
  55.     MOVEM.L    (SP)+,A0-A6/D1-D7
  56.     moveq    #ERR_OK,d0
  57.     rts
  58.  
  59. ;==========================================================================;
  60. ;                                 INITIALISE
  61. ;==========================================================================;
  62.  
  63.     ;Randomize star coordinates
  64.  
  65. Main:    lea    StarCoords,a0            ;a0 = Ptr to star co-ordinates.
  66.     move.w    #NSTARS-1,d7
  67.     move.l    DPKBase(pc),a6
  68. .loop1    move.w    #8192,d1
  69.     CALL    SlowRandom
  70.     move.w    d0,(a0)+
  71.     CALL    SlowRandom
  72.     move.w    d0,(a0)+
  73.     CALL    SlowRandom
  74.     move.w    d0,(a0)+
  75.     dbra    d7,.loop1
  76.  
  77.     ;Construct perspective table
  78.  
  79.     lea    PersTable,a0             ;a0 = ptr to perspective table.
  80.     moveq    #0,d1                    ;d1 = Starting at 0.
  81. .loop2    move.l    #$95FFFF,d2              ;d2 = $95FFFF
  82.     move.l    d1,d3                    ;d3 = d1
  83.     add.w    #300,d3                  ;d3 = ++300
  84.     divu    d3,d2                    ;d2 = ($95ffff)/d3
  85.     move.w    d2,(a0)+                 ;a0 = d2+
  86.     addq.w    #1,d1                    ;d1 = ++1
  87.     cmp.w    #8192,d1                 ;d1 = Equal to 8192?
  88.     bne.s    .loop2
  89.  
  90.     ;Construct plot tables for fast drawing.
  91.  
  92.     lea    PlotXTable,a0            ;a0 = X table - byte positions.
  93.     lea    PlotBTable,a1            ;a1 = Bit table (X related).
  94.     lea    PlotYTable,a2            ;a2 = Y table - line position.
  95.     moveq    #0,d0                    ;d0 = 00
  96. .loop3    move.w    d0,d1                    ;d1 = d0
  97.     lsr.w    #3,d1                    ;d1 = (d0)<<3
  98.     move.w    d1,(a0)+                 ;a0 = d1+
  99.  
  100.     move.w    d0,d1                    ;d1 = d0
  101.     eor.w    #$FFFF,d1                ;d1 = (d0) eor $ffff
  102.     and.w    #%00000111,d1            ;d1 = &%00000111
  103.     move.w    d1,(a1)+                 ;a1 = BitSet++
  104.  
  105.     cmp.w    #SCRHEIGHT,d0    ;Write out the Y values for the
  106.     bge.s    .plot2    ;table.
  107.     move.w    d0,d1    ;d1 = Line Number.
  108.     mulu    #80,d1    ;d1 = (LineNumber)*80
  109.     move.w    d1,(a2)+    ;a2 = (LineNumber*80)++
  110.  
  111. .plot2    addq.w    #1,d0
  112.     cmp.w    #SCRWIDTH,d0
  113.     bne.s    .loop3
  114.  
  115. ;==========================================================================;
  116. ;                                MAIN LOOP
  117. ;==========================================================================;
  118.  
  119. MainLoop:
  120.     move.l    SCRBase(pc),a6
  121.     CALL    scrWaitAVBL
  122.     move.l    Screen(pc),a0
  123.     CALL    scrSwapBuffers
  124.  
  125. ;==========================================================================;
  126. ;                             STAR ANIMATION
  127. ;==========================================================================;
  128.  
  129.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  130.     add.w    #XSPEED,d0               ;d0 = (StarXPos)+XSPEED
  131.     add.w    #YSPEED,d1               ;d1 = (StarYPos)+YSPEED
  132.     add.w    #ZSPEED,d2               ;d2 = (StarZPos)+ZSPEED
  133.     and.w    #%0000011111111111,d0
  134.     and.w    #%0000011111111111,d1
  135.     and.w    #%0000011111111111,d2
  136.     movem.w    d0/d1/d2,StarXPos
  137.  
  138.     lea    Sinus(pc),a0             ;a0 = Sinus table.
  139.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  140.     add.w    (a0,d0.w),d3
  141.     add.w    (a0,d1.w),d4
  142.     add.w    (a0,d2.w),d5
  143.     movem.w    d3/d4/d5,StarXAdd
  144.  
  145. ;===========================================================================;
  146. ;                              SCREEN CLEAR
  147. ;===========================================================================;
  148.  
  149.     move.l    DPKBase(pc),a6
  150.     move.l    Screen(pc),a1    ;a1 = GameScreen
  151.     move.l    GS_Bitmap(a1),a0    ;a0 = Bitmap
  152.     CALL    Clear
  153.  
  154. ;==========================================================================;
  155. ;                               DRAW STARS
  156. ;==========================================================================;
  157.  
  158.     move.l    DPKBase(pc),a6
  159.     move.l    Screen(pc),a0
  160.     CALL    Lock
  161.  
  162.     lea    StarCoords,a0            ;Draw starfield
  163.     lea    PersTable,a1
  164.     lea    PlotXTable,a2
  165.     lea    PlotBTable,a3
  166.     lea    PlotYTable,a4
  167.     move.l    Screen(pc),a6
  168.     move.l    GS_MemPtr2(a6),a6
  169.  
  170.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  171.     add.w    #4096,d3                 ;d3 = ++4096
  172.     add.w    #4096,d4                 ;d4 = ++4096
  173.  
  174.     move.w    #NSTARS-1,d7
  175.  
  176. .draw1    movem.w    (a0)+,d0/d1/d2           ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  177.     add.w    d3,d0                    ;Increase XPos.
  178.     and.w    #8191,d0                 ;d0 = And'd
  179.     sub.w    #4096,d0                 ;d0 = --4096
  180.  
  181.     add.w    d4,d1                    ;Y-movement
  182.     and.w    #8191,d1                 ;d1 = And'd
  183.     sub.w    #4096,d1                 ;d1 = --4096
  184.  
  185.     add.w    d5,d2                    ;Z-movement
  186.     and.w    #8191,d2
  187.     add.w    d2,d2                    ;d2 = *2 [word]
  188.     move.w    (a1,d2.w),d6             ;d6 = Read from Perspective table.
  189.  
  190.     muls    d6,d0                    ;X-projection
  191.     swap    d0
  192.     add.w    #176,d0
  193.  
  194.     cmp.w    #SCRWIDTH-1,d0
  195.     bhi.s    .nodraw
  196.     muls    d6,d1                    ;Y-projection
  197.     swap    d1
  198.     add.w    #136,d1
  199.     cmp.w    #SCRHEIGHT-1,d1
  200.     bhi.s    .nodraw
  201.  
  202.     add.w    d0,d0                    ;d0 = *2 [word]
  203.     add.w    d1,d1                    ;d1 = *2 [word]
  204.     move.w    (a4,d1.w),d6             ;d6 = Plot Y.
  205.     add.w    (a2,d0.w),d6             ;d6 = ++PlotX.
  206.     move.w    (a3,d0.w),d0             ;d0 = BitValue.
  207.  
  208.     cmp.w    #7000,d2                 ;Now draw the star according to
  209.     bgt.s    .draw2                   ;its position in the Z axis.
  210.     bset    d0,(a6,d6.w)
  211.     dbra    d7,.draw1
  212.     bra.s    .done
  213.  
  214. .draw2    cmp.w    #13000,d2
  215.     bgt.s    .draw3
  216.     bset    d0,SCRWIDTH/8(a6,d6.w)
  217.     dbra    d7,.draw1
  218.     bra.s    .done
  219.  
  220. .draw3    bset    d0,(a6,d6.w)
  221.     bset    d0,SCRWIDTH/8(a6,d6.w)
  222. .nodraw    dbra    d7,.draw1
  223.  
  224. .done    move.l    DPKBase(pc),a6
  225.     move.l    Screen(pc),a0
  226.     CALL    Unlock
  227.  
  228.     move.l    JoyData(pc),a0
  229.     CALL    Query
  230.     move.l    JoyData(pc),a0
  231.     move.l    JD_Buttons(a0),d0
  232.     sub.l    a1,a1
  233.     moveq    #$00,d1
  234.     btst    #JB_LMB,d0
  235.     beq    MainLoop
  236.     rts
  237.  
  238. ;===========================================================================;
  239. ;                                  DATA
  240. ;===========================================================================;
  241.  
  242. JoyData:    dc.l  0
  243.  
  244. ScreenTags:    dc.l  TAGS_SCREEN
  245. Screen:        dc.l  0
  246.         dc.l  GSA_Width,SCRWIDTH
  247.         dc.l  GSA_Height,SCRHEIGHT
  248.         dc.l  GSA_Attrib,SCR_TPLBUFFER
  249.         dc.l    GSA_BitmapTags,0
  250.         dc.l    BMA_Type,ILBM
  251.         dc.l    BMA_Palette,.palette
  252.         dc.l    TAGEND,0
  253.         dc.l  TAGEND
  254.  
  255. .palette    dc.l  PALETTE_ARRAY,4
  256.         dc.l  $000000,$D0D0D0,$606060,$202020
  257.  
  258. ;===========================================================================;
  259. ;                                STAR DATA
  260. ;===========================================================================;
  261.  
  262. StarXAdd:    dc.w  33                       ;Star stuff
  263. StarYAdd:    dc.w  12
  264. StarZAdd:    dc.w  -114
  265. StarXPos:    dc.w  0                        ;Sinus positions
  266. StarYPos:    dc.w  310
  267. StarZPos:    dc.w  1280
  268.  
  269.     INCLUDE    "GMSDev:source/asm/demos/StarSinus.i"
  270.  
  271.     SECTION    Storage,BSS
  272.  
  273. StarCoords:    ds.w  NSTARS*3    ;Star coordinates
  274. PersTable:    ds.w  8192    ;Perspective table
  275. PlotXTable:    ds.w  SCRWIDTH    ;Plot tables
  276. PlotBTable:    ds.w  SCRWIDTH
  277. PlotYTable:    ds.w  SCRHEIGHT
  278.  
  279. ;===========================================================================;
  280.  
  281. ProgName:    dc.b  "3D Starfield 4",0
  282. ProgAuthor:    dc.b  "Paul Manias",0
  283. ProgDate:    dc.b  "January 1998",0
  284. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1998.  Freely distributable.",0
  285. ProgShort:    dc.b  "4 colour star field demonstration.",0
  286.         even
  287.  
  288.